/******************************************************************************* * Copyright (c) 2005, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.ui.internal.dialogs; import java.util.Collection; import java.util.HashSet; import org.eclipse.jface.preference.IPreferenceNode; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; /** * The PreferenceNodeFilter is a filter that only matches * a set of ids. */ public class PreferenceNodeFilter extends ViewerFilter { Collection ids = new HashSet(); /** * Create a new instance of the receiver on a * list of filteredIds. * @param filteredIds The collection of ids that * will be shown. */ public PreferenceNodeFilter(String[] filteredIds) { super(); for (String filteredId : filteredIds) { ids.add(filteredId); } } @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return checkNodeAndChildren((IPreferenceNode) element); } /** * Check to see if the node or any of its children * have an id in the ids. * @param node WorkbenchPreferenceNode * @return boolean <code>true</code> if node or oe of its children * has an id in the ids. */ private boolean checkNodeAndChildren(IPreferenceNode node) { if(ids.contains(node.getId())) { return true; } for (IPreferenceNode subNode : node.getSubNodes()) { if(checkNodeAndChildren(subNode)) { return true; } } return false; } }